<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="开始时间：">
              <el-date-picker
                v-model="form.startDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间：">
              <el-date-picker
                v-model="form.endDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="商户名称：">
              <el-input
                v-model="form.pointName"
                style="width: 180px"
              ></el-input>
            </el-form-item>
            <el-form-item label="确认状态：">
              <el-select
                v-model="form.order"
                placeholder="请选择"
                style="width: 180px"
              >
                <el-option
                  v-for="item in select.OrderType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getTableData"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="showTableDataAlarm"
              >逾期未申请列表</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
    >
      <el-table-column
        prop="商户名称"
        label="商户名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="变更后状态"
        label="变更后状态"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="变更说明"
        label="变更说明"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="正式变更日期"
        label="正式变更日期"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="确认状态"
        label="确认状态"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-success"
            v-if="scope.row.确认状态 === '待确认'"
            @click="handleSign(scope.$index, scope.row)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '../../assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      tableData: [],
      tableDataAlarm: [],
      form: {
        startDate: formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24 * 30), 'yyyy-MM-dd'),
        endDate: formatDate(new Date(new Date().getTime() + 3600 * 1000 * 24), 'yyyy-MM-dd'),
        pointName: '',
        order: '-1',
      },
      formRow: {},
      select: {
        OrderType: [{
          value: '-1',
          label: '全部'
        }, {
          value: '0',
          label: '待确认'
        }, {
          value: '1',
          label: '已确认'
          // }, {
          //   value: '2',
          //   label: '驳回'
        }],
      },
    }
  },
  mounted () {
    this.getTableData();
  },
  methods: {
    async updateApplyStatus (pointID) {
      var url = 'Sign/UpdataPlaceOpenIsCheck?POINT_ID=' + pointID
      const { data } = await this.$Http.get(url)
      if (data.IsSucess) {
        this.$message.success('申请审核成功')
        this.getTableData()
      } else {
        this.$message.error('审核失败，请重新审核')
      }
    },
    async getTableData () {
      var url = 'Sign/GetPointOpenInfo?ClientNo=' + localStorage.getItem('CLIENT_NO')
        + '&StartDate=' + this.form.startDate + '&EndDate=' + this.form.endDate + '&isOK=' + this.form.order + '&PointName=' + this.form.pointName
      const { data } = await this.$Http.get(url)
      this.tableData = data
    },
    // 签批
    handleSign (index, row) {
      this.$confirm('确认同意此申请？', '提示', {
        confirmButtonText: '同意',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.updateApplyStatus(row.POINT_ID)
      }).catch(() => {
      });
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
    },
    handleSizeChange (size) {
      this.pageSize = size;
      this.currentPage = 1;
    },
  }
}
</script>
